#include "heard.h"


int analyse(char *strs, int net_fd){

    char *command = strtok(strs, " ");
    for(;;){
        if(memcmp("puts", command, strlen(command)) == 0){
          //  upload file
            

        }else if(memcmp("Y", command, strlen(command)) == 0){
            // login

            char username[10];
            char passward[MAXSIZE];
            bzero(username, sizeof(username));
            bzero(passward, sizeof(passward));

            recv(net_fd, username, sizeof(username), 0);
            recv(net_fd, passward, sizeof(passward), 0);
            if(login_client(username, passward)){
                send(net_fd, "s", sizeof(char), 0);
            }else{
                send(net_fd, "f", sizeof(char), 0);
            }
        }else if(memcmp("R", command, strlen(command)) == 0){
            // registered

            char username[10];
            char passward[MAXSIZE];
            bzero(username, sizeof(username));
            bzero(passward, sizeof(passward));

            recv(net_fd, username, sizeof(username), 0);
            recv(net_fd, passward, sizeof(passward), 0);
            if(registered(username, passward)){
                send(net_fd, "s", sizeof(char), 0);
            }else{
                send(net_fd, "f", sizeof(char), 0);
            }

        }/*else if (memcmp("gets", command, strlen(command)) == 0){
            // load file


            char *filename = strtok(NULL, " ");
            if(load_file(net_fd, filename)== -1){
                char *funcname = "load_file";
                log_write(funcname,ERRORS);
            }
        }*/
    }

    return 0;
}
